package com.funo.wcity.app.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.funo.wcity.app.entity.TblCompanies;

@Repository("tblCompaniesDAO")
public class TblCompaniesDAO extends DefaultBaseDao<TblCompanies,Integer>{
	
	/**
	 * 查询公司列表
	 * @param
	 * 		idUser
	 * 			用户id
	 */
	public List getTblCompaniesList(Integer idEmployee){
		String hql="From TblCompanies t where t.idEmployee in("+idEmployee+")";
		return this.hibernateTemplate.find(hql);
	}
	
	
	/**
	 * 查询公司列表
	 * @param
	 * 		idEmployees
	 * 			员工ID
	 * @param
	 * 		idCompanyType
	 * 			公司类型
	 */
	public List getTblCompaniesList(String idEmployees,Integer idCompanyType){
		StringBuffer sql=new StringBuffer("select c.* from tblcompanytypes type,tblcompanies c where type.idCompanyType=c.idCompanyType "+
						"and type.idCompanyType="+idCompanyType+" and c.idEmployee in("+idEmployees+") order by c.lastDate");
		return this.jdbcTemplate.queryForList(sql.toString());
	}
	
	/**
	 * 查询公司列表
	 * @param
	 * 		idEmployees
	 * 			员工ID
	 */
	public List getTblCompaniesList(String idEmployees){
		StringBuffer sql=new StringBuffer("select c.* from tblcompanies c where c.idEmployee in("+idEmployees+") order by c.lastDate");
		return this.jdbcTemplate.queryForList(sql.toString());
	}
	
	public TblCompanies getTblCompaniesByIdContactPerson(Integer idContactPersons){
		String hql = "from TblCompanies t where t.idCompany in (select c.tblcompanies.idCompany from TblContactPersons c where c.idContactPerson = "+idContactPersons+")";
		return (TblCompanies)this.hibernateTemplate.find(hql).get(0);
	}
}
